<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%--引用js即可使用ckeditor--%>
<script src="${pageContext.request.contextPath}/static/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jQuery.js"></script>

<script>
    function checkForm() {
        var title = $("#title").val();
        var content = CKEDITOR.instances.content.getData();
        var typeId = $("#typeId").val();
        if(title=="" || title==null){
            $("#error").html("标题不能为空！");
            return false;
        }
        if(content=="" || content==null){
            $("#error").html("内容不能为空!");
            return false;
        }
        if(typeId=="" || typeId==null){
            $("#error").html("请选择类别!");
            return false;
        }
        return true;
    }
</script>

<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="data_list">
    <div class="data_list_title">
        <c:if test="${diary!=null}">
            <img src="${pageContext.request.contextPath}/static/images/diary_type_edit_icon.png"/>修改日记
        </c:if>
        <c:if test="${diary==null}">
            <img src="${pageContext.request.contextPath}/static/images/diary_add_icon.png"/>写日记
        </c:if>
    </div>
    <form action="diary?action=save" method="post" onsubmit="return checkForm()">
        <div class="diary_datas">
            <div class="diary_title">
                <input type="text" id="title" name="title" value="${diary.title}" class="input-xlarge" style="height: 30px;" placeholder="日志标题...">
            </div>
            <div>
                <textarea class="ckeditor" id="content" name="content">${diary.content}</textarea>
            </div>
            <div class="diary_type">
                <select name="typeId" id="typeId">
                    <option value="">请选择日志类别...</option>
                    <c:forEach var="diaryType" items="${diaryTypeCountList}">
                        <option value="${diaryType.diaryTypeId}" ${diaryType.diaryTypeId==diary.typeId?'selected':''}>${diaryType.typeName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="diary_action">
                <input type="hidden" id="diaryId" name="diaryId" value="${diary.diaryId}">
                <button class="btn btn-primary" type="submit">保存</button>
                <button class="btn btn-primary" type="button" onclick="window.history.back()">返回</button>
                <span id="error" style="color:red">${error}</span>
            </div>
        </div>
    </form>
</div>
</body>
</html>
